package com.wei.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wei.client.CourseOrderFeign;
import com.wei.client.MemberOrderFeign;
import com.wei.entity.Order;
import com.wei.service.OrderService;
import com.wei.mapper.OrderMapper;
import com.wei.service_base.vo.CourseOrderVo;
import com.wei.service_base.vo.MemberOrderVo;
import com.wei.util.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author HASEE
 * @description 针对表【t_order(订单)】的数据库操作Service实现
 * @createDate 2022-12-04 04:41:46
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
        implements OrderService {
    @Autowired
    private CourseOrderFeign courseOrderFeign;

    @Autowired
    private MemberOrderFeign memberOrderFeign;

    @Override
    public String createOrderInfo(String courseId, String uid) {

        //根据课程id查询课程相关信息
        CourseOrderVo course = courseOrderFeign.getCourseOrderInfo(courseId);

        //根据用户id查询用户信息
        MemberOrderVo member = memberOrderFeign.getMemberOrderInfo(uid);

        Order order = new Order();

        order.setOrderNo(OrderNoUtil.getOrderNo()); // 订单号

        order.setCourseId(courseId);
        order.setCourseTitle(course.getTitle());
        order.setCourseCover(course.getCover());
        order.setTeacherName(course.getTeacherName());
        order.setTotalFee(course.getPrice());
        order.setMemberId(uid);
        order.setMobile(member.getMobile());
        order.setNickname(member.getNickname());

        order.setStatus(0); //支付状态 0未支付 1已支付
        order.setPayType(1); //支付类型。1代表微信

        baseMapper.insert(order);

        return order.getOrderNo();
    }
}




